Skip to content

Don't auto-scroll horizontal drag-selection in the top/bottom rows#895

Open
hexbinoct wants to merge 1 commit into
microsoft:mainfrom
hexbinoct:fix/horizontal-select-edge-scroll
Open

Don't auto-scroll horizontal drag-selection in the top/bottom rows#895
hexbinoct wants to merge 1 commit into
microsoft:mainfrom
hexbinoct:fix/horizontal-select-edge-scroll

Conversation

@hexbinoct

Copy link
Copy Markdown

Fixes #32.

Problem

While drag-selecting, the view auto-scrolls whenever the mouse is within the scroll zone near an edge (up to 3 cells). The trigger only looked at the mouse position, not at where the drag started. So if you start a selection in the top or bottom rows and move the mouse only horizontally, the view scrolls vertically, and a horizontal selection in those rows becomes impossible.

Fix

Anchor the scroll trigger to the drag start position. When a drag begins inside a scroll zone, the trigger point is pulled to the start position, so:

  • Moving only along the other axis (for example a purely horizontal drag in the top/bottom rows) no longer forces a scroll.
  • The scroll speed ramps up from where the drag began instead of snapping to full speed.

When the drag starts outside the scroll zones, the behavior is unchanged.

This follows the approach @DHowett and @lhecker outlined in the issue (trigger from min(start, edge) / max(start, edge) rather than from the edge alone).

Notes

The per-axis speed calculation, which used to be a closure inside the event handler, is now a small drag_scroll_speed free function. That made it possible to add unit tests for the edge cases: no scroll in the middle, edge-triggered scrolling from a middle start (unchanged behavior), no scroll when a drag in an edge zone only moves horizontally, and continued scrolling once the mouse passes the start position.

Testing

  • cargo test -p edit --lib passes (46 tests, including the 4 new drag_scroll_speed cases).
  • cargo clippy -p edit --lib is clean.
  • cargo fmt clean on the changed code.

The drag-selection auto-scroll triggered whenever the mouse sat within the
top/bottom (or left/right) scroll zone, regardless of where the drag began.
Starting a selection in the top or bottom rows and moving only horizontally
therefore scrolled the view vertically, which made a horizontal selection in
those rows impossible.

Anchor the scroll trigger to the drag start position: when a drag begins
inside a scroll zone, the trigger point moves to the start, so movement along
the other axis alone no longer scrolls, and the speed ramps up from where the
drag began instead of snapping to full speed. When the drag begins outside the
zones the behavior is unchanged.

The scroll-speed calculation is extracted into a testable drag_scroll_speed
function with unit tests covering the edge cases.

Fixes microsoft#32
@hexbinoct

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Horizontal selection is impossible in the top/bottom 3 lines

1 participant